<#
框架演进（原生 PowerShell）
用途：支持 verify/apply 两种模式，校验并追加 docs/meta_index.md 的框架条目。
用法：
  pwsh -File scripts/windows/framework_evolve.ps1 verify|apply
#>
param([Parameter(Mandatory=$true)][ValidateSet('verify','apply')][string]$mode)

$WindowsDir = Split-Path -Parent $PSCommandPath
$ScriptsDir = Split-Path -Parent $WindowsDir
$RepoDir = Split-Path -Parent $ScriptsDir

$meta = Join-Path $RepoDir 'docs/meta_index.md'
$items = @('docs/framework_changes.md','rules/project_rules.md','rules/framework_info.md')

if (!(Test-Path $meta)) { Write-Error "缺少 meta_index：$meta"; exit 2 }
$raw = Get-Content -Raw $meta
$miss = $items | Where-Object { $raw -notmatch [regex]::Escape($_) }

if ($mode -eq 'verify') {
  if ($miss.Count -gt 0) { Write-Warning "缺失条目：`n - " + ($miss -join "`n - "); exit 2 } else { Write-Host "框架演进验证通过"; exit 0 }
} else {
  if ($miss.Count -eq 0) { Write-Host "无需追加，已完整"; exit 0 }
  $append = "`n# 框架演进追加（AI 脚本）`n" + ($miss | ForEach-Object { "- $_" }) -join "`n"
  Add-Content -Path $meta -Value $append
  Write-Host "已追加缺失条目：`n - " + ($miss -join "`n - ")
  exit 0
}
